package entityAdapter

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commSql"
	"sync"
)

type vacuumAdapter struct {
	count int64
	mutex sync.Mutex
}

func (e *vacuumAdapter) Accumulate(count int64) {
	// 限制并发
	e.mutex.Lock()
	defer e.mutex.Unlock()

	e.count += count
}

func (e *vacuumAdapter) Vacuum() {
	// 限制并发
	e.mutex.Lock()
	defer e.mutex.Unlock()

	if e.count < 10*10000 {
		return
	}

	// 如果是sqlite，那么还要执行压缩命令
	if commSql.GetDBType() == "sqlite3" {
		commSql.Client.Exec("VACUUM;", nil)
	}

	e.count = 0
}
